package com.yanqu.road.dao.impl.activity.peakseacraft;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.peakseacraft.config.PeakSeacraftDonateConfig;
import com.yanqu.road.entity.activity.peakseacraft.config.PeakSeacraftLastGuessConfig;
import com.yanqu.road.entity.activity.peakseacraft.config.PeakSeacraftRoundScoreConfig;
import com.yanqu.road.entity.activity.seacraft.config.SeacraftSouthSeaBattleConfig;
import com.yanqu.road.entity.activity.seacraft.config.SeacraftSouthSeaFloorConfig;
import com.yanqu.road.entity.activity.seacraft.config.SeacraftSouthSeaGuessConfig;
import com.yanqu.road.entity.activity.seacraft.config.SeacraftSouthSeaShipConfig;
import com.yanqu.road.entity.config.system.PropertyWeightItem;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 */
public class PeakSeacraftConfigDaoImpl extends TempDao {

    private static String getPeakSeacraftDonateConfigSql = "select * from `t_s_activity_peakseacraft_dona` where `activityId`=?";
    public List<PeakSeacraftDonateConfig> getPeakSeacraftDonateConfigList(int activityId) {
        List<PeakSeacraftDonateConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getPeakSeacraftDonateConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                PeakSeacraftDonateConfig peakSeacraftDonateConfig = new PeakSeacraftDonateConfig();
                peakSeacraftDonateConfig.setActivityId(rs.getInt("activityId"));
                peakSeacraftDonateConfig.setId(rs.getInt("id"));
                peakSeacraftDonateConfig.setCost(rs.getString("cost"));
                peakSeacraftDonateConfig.setAddPro(rs.getInt("addPro"));
                list.add(peakSeacraftDonateConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getPeakSeacraftRoundScoreConfigSql = "select * from `t_s_activity_peakseacraft_score` where `activityId`=?";
    public List<PeakSeacraftRoundScoreConfig> getPeakSeacraftRoundScoreConfigList(int activityId) {
        List<PeakSeacraftRoundScoreConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getPeakSeacraftRoundScoreConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                PeakSeacraftRoundScoreConfig peakSeacraftRoundScoreConfig = new PeakSeacraftRoundScoreConfig();
                peakSeacraftRoundScoreConfig.setActivityId(rs.getInt("activityId"));
                peakSeacraftRoundScoreConfig.setArea(rs.getInt("area"));
                peakSeacraftRoundScoreConfig.setRound(rs.getInt("round"));
                peakSeacraftRoundScoreConfig.setRank(rs.getInt("rank"));
                peakSeacraftRoundScoreConfig.setScore(rs.getInt("score"));
                list.add(peakSeacraftRoundScoreConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getPeakSeacraftLastGuessConfigSql = "select * from `t_s_activity_seacraft_lastguess` where `activityId`=?";
    public List<PeakSeacraftLastGuessConfig> getPeakSeacraftLastGuessConfigList(int activityId) {
        List<PeakSeacraftLastGuessConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getPeakSeacraftLastGuessConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                PeakSeacraftLastGuessConfig peakSeacraftLastGuessConfig = new PeakSeacraftLastGuessConfig();
                peakSeacraftLastGuessConfig.setActivityId(rs.getInt("activityId"));
                peakSeacraftLastGuessConfig.setId(rs.getInt("id"));
                peakSeacraftLastGuessConfig.setCount(rs.getString("count"));
                peakSeacraftLastGuessConfig.setDesc(rs.getString("desc"));
                peakSeacraftLastGuessConfig.setAward(rs.getString("award"));
                peakSeacraftLastGuessConfig.setShow(rs.getInt("show"));
                list.add(peakSeacraftLastGuessConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
